package blue.mqtt4j.client;

import blue.mqtt4j.client.codec.Decoder;
import blue.mqtt4j.internal.client.impl.DefaultMqttClient;

import java.util.List;

/**
 * @author Jin Zheng
 * @since 1.0 2020-09-30
 */
public interface MqttClient
{

	static MqttClient newClient(String broker, MqttOptions options)
	{
		return new DefaultMqttClient(broker, options);
	}

	void connect();

	void close();

	Producer getProducer();

	MqttOptions getOptions();

	default void subscribe(MqttTopic topic, ConsumerListener listener)
	{
		this.subscribe(List.of(topic), null, listener);
	}

	default void subscribe(MqttTopic topic, Decoder decoder, ConsumerListener listener)
	{
		this.subscribe(List.of(topic), decoder, listener);
	}

	default void subscribe(List<MqttTopic> topicList, ConsumerListener listener)
	{
		this.subscribe(topicList, null, listener);
	}

	void subscribe(List<MqttTopic> topicList, Decoder decoder, ConsumerListener listener);

	void unsubscribe(String topic);

	void setConnectionListener(ConnectionListener listener);


}
